home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / samples / grtask / task.h < prev   
C/C++ Source or Header  |  1992-10-28  |  1KB  |  61 lines

  1. #ifndef _task_h_
  2. #define _task_h_
  3.  
  4. #include <setjmp.h>
  5.  
  6. typedef int (TaskProc)(int, void*);
  7.  
  8.  
  9. class Task {
  10.   public:
  11.   Task *prev; // links into run-state queues
  12.   Task *next;
  13.   Task *parent;
  14.  
  15.   jmp_buf state;
  16.  
  17.   unsigned *stack;
  18.   unsigned stack_len;
  19.  
  20.   enum RunState {
  21.     Running,
  22.     Blocked,
  23.     Waiting,
  24.     Dead
  25.   };
  26.   RunState run_state;
  27.  
  28.   int ret_val;
  29.  
  30.   friend int fall_off_end();
  31.  
  32. public:
  33.   
  34.   Task(TaskProc proc=0, int val=0, void* ptr=0, int stacksize=9999,
  35.               int priviliged=0);
  36.                   // use default proc in main() to setup initial task
  37.                   /* Val and ptr are passed into TaskProc when it begins */
  38.                 /* to execute.   If proviliged is nonzero, the task will */
  39.                 /* be executed once for every call to Yield(). */
  40.   ~Task();
  41.   
  42.   int ReturnValue();
  43.   
  44.   friend int Wait(Task* child=0);
  45.   friend void Return(int rv=0);
  46.       /* All child tasks are killed when a task returns. */
  47.   friend void Yield();
  48.   friend void Block(Task **my_task_ptr);
  49.               /* This task won't execute until unblock() is called. */
  50.             /* My_task_ptr points to a place to put an identifier for */
  51.             /* this task; you'll need it to unblock.  Usually used as */
  52.             /* Task *p; Block(&p); ....... Unblock(p); */
  53.             /* Execution doesn't make it out of Block() until Unblock() */
  54.             /* is called (from another task). */
  55.   friend void Unblock(Task *blocked_task);
  56.   friend void Kill(Task *victim_task, int rv=0);
  57.             /* Equivalent to having the victim task call Return(rv) */
  58. };
  59.  
  60. #endif
  61.